package cn.luischen.controller.admin;

import cn.luischen.constant.LogActions;
import cn.luischen.constant.WebConst;
import cn.luischen.controller.BaseController;
import cn.luischen.model.OptionsDomain;
import cn.luischen.service.log.LogService;
import cn.luischen.service.option.OptionService;
import cn.luischen.utils.APIResponse;
import cn.luischen.utils.GsonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import java.lang.reflect.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import java.util.Map;
import java.util.List;
import com.unitspirit.runtime.*;

/**
 * The class contains tests for the class cn.luischen.controller.admin.SettingController.
 *
 * @generatedBy UnitSpirit CreateTemplateTestFile4
 * @version 1.0.9.11 
 */
@PowerMockIgnore({ "javax.management.*" })
@RunWith(PowerMockRunner.class)
@PrepareForTest({ cn.luischen.utils.GsonUtils.class,
		cn.luischen.utils.APIResponse.class })
public class SettingController_saveSetting_WGTest {
	@Rule
	public ExpectedException unitspirit_thrown = ExpectedException.none();

	/**
	 * 测试方法初始化.
	 * 
	 * @throws Exception 
	 *         if the initialization fails for some reason 
	 *  
	 * @generatedBy UnitSpirit at 2021-12-08 11:01:22
	 */
	@org.junit.Before
	public void setUp() throws Exception {
		try {
			GlobalUnitInit.init();
			MockitoAnnotations.initMocks(this);
			ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	@InjectMocks
	cn.luischen.controller.admin.SettingController unitspirit_fixture;

	@Mock
	cn.luischen.service.option.OptionService mock_OptionService;
	@Mock
	cn.luischen.service.log.LogService mock_LogService;

	/**
	 * @date 2021-12-08 11:01:22
	 * @see cn.luischen.controller.admin.SettingController#saveSetting
	 * @category null  
	 * @author UnitSpirit   
	 */
	@Test
	public void test_saveSetting_1207_114135_883_2_01() throws Throwable {
		unitspirit_fixture = PowerMockito.spy(unitspirit_fixture);
		//被测函数参数定义
		javax.servlet.http.HttpServletRequest HttpServletRequest_p_0 = Mockito
				.mock(javax.servlet.http.HttpServletRequest.class);
		//成员变量设置

		//返回值定义 
		String result_expected = "{\"code\":\"success\"}";

		java.util.Map<String, String> Mapmock5_0 = JSON
				.parseObject(
						"{\"google_site_verification\":\"\",\"site_record\":\"\",\"baidu_site_verification\":\"\",\"site_description\":\"123\",\"allow_install\":\"\",\"site_title\":\"\"}",
						java.util.Map.class);
		PowerMockito.mockStatic(cn.luischen.utils.GsonUtils.class);
		java.lang.String mock_result_String4 = "{\"site_record\":\"\",\"google_site_verification\":\"\",\"site_description\":\"123\",\"baidu_site_verification\":\"\",\"site_title\":\"\",\"allow_install\":\"\"}";
		Integer mock_result_Integer3 = 1;
		PowerMockito
				.doReturn(mock_result_Integer3)
				.when(unitspirit_fixture)
				.getUid(Mockito
						.any(javax.servlet.http.HttpServletRequest.class));
		String Stringmock2_0 = "保存系统设置";
		String Stringmock2_1 = "{\"site_record\":\"\",\"google_site_verification\":\"\",\"site_description\":\"123\",\"baidu_site_verification\":\"\",\"site_title\":\"\",\"allow_install\":\"\"}";
		String Stringmock2_2 = "127.0.0.1";
		Integer Integermock2_3 = 1;
		PowerMockito.mockStatic(cn.luischen.utils.APIResponse.class);
		cn.luischen.utils.APIResponse mock_result_APIResponse1 = JSON
				.parseObject("{\"code\":\"success\"}",
						cn.luischen.utils.APIResponse.class);

		PowerMockito.doNothing().when(mock_OptionService)
				.saveOptions(Mockito.any(java.util.Map.class));
		PowerMockito
				.when(cn.luischen.utils.GsonUtils.toJsonString(anyObject()))
				.thenReturn(mock_result_String4);
		PowerMockito
				.doNothing()
				.when(mock_LogService)
				.addLog(anyString(), anyString(), anyString(), Mockito.anyInt());
		PowerMockito.when(cn.luischen.utils.APIResponse.success()).thenReturn(
				mock_result_APIResponse1);

		cn.luischen.utils.APIResponse unitspirit_result = unitspirit_fixture
				.saveSetting(HttpServletRequest_p_0);
		cn.luischen.utils.APIResponse obj_expected = JSON.parseObject(
				result_expected, cn.luischen.utils.APIResponse.class);
		UnitAssert.assertEquals(
				UnitSpiritFastJsonUtil.getJsonString2(obj_expected),
				UnitSpiritFastJsonUtil.getJsonString2(unitspirit_result));
	}
  /**
  * @date 2021-12-08 11:01:22
  * @see cn.luischen.controller.admin.SettingController#saveSetting
  * @category null  
  * @author UnitSpirit   
  */
  @Test
  public void test_saveSetting_1207_114141_103_2_01() throws Throwable {
    unitspirit_fixture = PowerMockito.spy(unitspirit_fixture);
    //被测函数参数定义
    javax.servlet.http.HttpServletRequest HttpServletRequest_p_0 = Mockito.mock(javax.servlet.http.HttpServletRequest.class);
  //成员变量设置


    //返回值定义 
    String result_expected = "{\"code\":\"success\"}";

    java.util.Map<String,String> Mapmock5_0 =  JSON.parseObject("{\"social_zhihu\":\"123\",\"social_jianshu\":\"\",\"social_resume\":\"\",\"social_github\":\"\",\"social_twitter\":\"\",\"social_csdn\":\"\",\"social_weibo\":\"\"}",java.util.Map.class);
    PowerMockito.mockStatic(cn.luischen.utils.GsonUtils.class);
    java.lang.String mock_result_String4 = "{\"social_zhihu\":\"123\",\"social_resume\":\"\",\"social_jianshu\":\"\",\"social_github\":\"\",\"social_twitter\":\"\",\"social_csdn\":\"\",\"social_weibo\":\"\"}";
    Integer mock_result_Integer3 = 1;
    PowerMockito.doReturn( mock_result_Integer3).when(unitspirit_fixture).getUid(Mockito.any(javax.servlet.http.HttpServletRequest.class ));
    String Stringmock2_0 = "保存系统设置";
    String Stringmock2_1 = "{\"social_zhihu\":\"123\",\"social_resume\":\"\",\"social_jianshu\":\"\",\"social_github\":\"\",\"social_twitter\":\"\",\"social_csdn\":\"\",\"social_weibo\":\"\"}";
    String Stringmock2_2 = "127.0.0.1";
    Integer Integermock2_3 = 1;
    PowerMockito.mockStatic(cn.luischen.utils.APIResponse.class);
    cn.luischen.utils.APIResponse mock_result_APIResponse1 =  JSON.parseObject("{\"code\":\"success\"}",cn.luischen.utils.APIResponse.class);

    PowerMockito.doNothing().when(mock_OptionService).saveOptions(Mockito.any(java.util.Map.class ));
    PowerMockito.when(cn.luischen.utils.GsonUtils.toJsonString(anyObject())).thenReturn( mock_result_String4);
    PowerMockito.doNothing().when(mock_LogService).addLog(anyString(),anyString(),anyString(),Mockito.anyInt());
    PowerMockito.when(cn.luischen.utils.APIResponse.success()).thenReturn( mock_result_APIResponse1);

    cn.luischen.utils.APIResponse  unitspirit_result =  unitspirit_fixture.saveSetting(HttpServletRequest_p_0);
    cn.luischen.utils.APIResponse obj_expected = JSON.parseObject(result_expected,cn.luischen.utils.APIResponse.class);
    UnitAssert.assertEquals(UnitSpiritFastJsonUtil.getJsonString2(obj_expected),UnitSpiritFastJsonUtil.getJsonString2(unitspirit_result));
  }
}